function setup_sltoolbox(target)
%INSTALL_PATHS Installs the paths of modules in the toolbox to MATLAB env
%
% [ Syntax ]
%   - setup_sltoolbox
%   - setup_sltoolbox path
%   - setup_sltoolbox mex
%
% [ Description ]
%   - setup_sltoolbox installs the toolbox into your MATLAB environment,
%     which typically adds paths of the related folders. The same as
%     setup_sltoolbox path.
%
%   - setup_sltoolbox path  adds the paths to MATLAB.
%
%   - setup_sltoolbox mex  compiles MEX files. 
% 
% Created by Dahua Lin, on Nov 19, 2007
%


%% takes input argument

if nargin == 1
    assert(ischar(target), 'the input argument should be a string.');
else
    target = 'path';
end

switch target
    case 'path'
        setup_paths;
    case 'mex'
        setup_mex;
    otherwise
        error('Unknown target name %s', target);
end
    


function setup_paths()


subdirs = { ...
    'classify', ...
    'cluster', ...
    'compute', ...
    'distrib', ...
    'fileio', ...
    'graph', ...
    'linops', ...
    'perfeval', ...
    'regression', ...
    'subspace', ...
    'utils'};

pa = fileparts(mfilename('fullpath'));

dirpaths = cellfun(@(x) fullfile(pa, x), subdirs, 'UniformOutput', false);

addpath(dirpaths{:});
savepath;


function setup_mex()

mexs = { ...
    {'compute/private', 'expandscalars_cimp.cpp'}, ...
    {'compute/private', 'pwhamming_cimp.cpp'}, ...
    {'compute/private', 'pwmetrics_cimp.cpp'}, ...
    {'compute/private', 'is_all_zeros_cimp.cpp'}, ...
    {'utils/private',   'arrayslice_cimp.cpp'}};

disp('Compile mex files:');

for i = 1 : numel(mexs)
    
    cdir = mexs{i}{1};
    cfile = mexs{i}{2};
    
    [pathstr, name] = fileparts(cfile);
    
    srcpath = fullfile(cdir, cfile);
    outpath = fullfile(cdir, name);
    
    fprintf('\tcompile %s ...\n', outpath); 
    
    mex('-output', outpath, '-O', srcpath);
    
end









